<?php
class Controller extends CController {
	public $breadcrumbs;
	/**
	 * 是否固定header.通常由View传递给main来指示是否固定header元素在浏览器顶部
	 * @var boolean;
	 */
	public $headerFixTop = true;
	/**
	 * 是否默认加载coreCss
	 * @var boolean
	 */
	public $coreCss = true;
	
	public function showSuccess($message, $url = array()) {
		$this->showMessage ( $message, $url, 'success' );
	}
	public function showError($message, $url = array()) {
		$this->showMessage ( $message, $url, 'error' );
	}
	/**
	 * 返回信息, 可以根据 url参数返回现实形式, ajax返回json数据, 默认返回网页html
	 *
	 * @param string|array $message
	 *        	返回的信息,可以是一条信息
	 * @param array $url
	 *        	跳转路径,默认为上一级浏览的网页
	 * @param string $type
	 *        	返回的类型
	 */
	public function showMessage($message, $url = array(), $type = 'error') {
		$request = Yii::app ()->request;
		if ($request->getIsAjaxRequest ()){
			$message = array(
				'success' => $type == 'success',
				'message' => $message
			);
			echo json_encode($message);
		}else {
			if (! is_array ( $message ))
				$message = array (
					$message 
				);
			$this->render ( '//_common/showMessage', array (
				'message' => $message,
				'url' => $url,
				'type' => $type 
			) );
		}
		Yii::app ()->end ();
	}
}